/*
* @Author: An
* @Date:   2017-07-14 10:08:11
* @Last Modified by:   An
* @Last Modified time: 2017-07-15 11:39:36
*/

'use strict';
var _xj = require('util/xj.js');

var _cart = {
	// 获取购物车中商品数量
	getCartCount : function(resolve, reject) {
		_xj.request({
			url 	: _xj.getServerUrl('/cart/get_cart_product_count.do'),
			success : resolve,
			error 	: reject 
		});
	},
	// 添加到购物车
	addToCart : function(productInfo, resolve, reject) {
		_xj.request({
			url 	: _xj.getServerUrl('/cart/add.do'),
			method	: 'POST',
			data 	: productInfo,
			success : resolve,
			error 	: reject
		});
	},
	// 获取购物车列表
	getCartList : function(resolve, reject) {
		_xj.request({
			url 	: _xj.getServerUrl('/cart/list.do'),
			success : resolve,
			error 	: reject 
		});
	},
	// 选择购物车商品
	selectProduct : function(productId, resolve, reject) {
		_xj.request({
			url 	: _xj.getServerUrl('/cart/select.do'),
			data	: {
				productId : productId
			},
			method	: 'POST',
			success : resolve,
			error 	: reject 
		});
	},
	// 取消选择购物车商品
	unselectProduct : function(productId, resolve, reject) {
		_xj.request({
			url 	: _xj.getServerUrl('/cart/un_select.do'),
			data	: {
				productId : productId
			},
			method	: 'POST',
			success : resolve,
			error 	: reject 
		});
	},
	// 全选购物车商品
	selectAllProduct : function(resolve, reject) {
		_xj.request({
			url 	: _xj.getServerUrl('/cart/select_all.do'),
			success : resolve,
			error 	: reject 
		});
	},
	// 取消全选购物车商品
	unselectAllProduct : function(resolve, reject) {
		_xj.request({
			url 	: _xj.getServerUrl('/cart/un_select_all.do'),
			success : resolve,
			error 	: reject 
		});
	},
	// 更新购物车商品数量
	updateProduct : function(productInfo, resolve, reject) {
		_xj.request({
			url 	: _xj.getServerUrl('/cart/update.do'),
			data	: productInfo,
			method	: 'POST',
			success : resolve,
			error 	: reject 
		});
	},
	// 删除指定商品（支持批量）
	deleteProduct : function(productIds, resolve, reject) {
		_xj.request({
			url 	: _xj.getServerUrl('/cart/delete_product.do'),
			data	: {
				productIds : productIds
			},
			method	: 'POST',
			success : resolve,
			error 	: reject 
		});
	},
}
module.exports = _cart;